package com.be.beadmin.system.controller.ProjectDesignController;

import com.be.beadmin.common.exception.BeadminException;
import com.be.beadmin.common.utils.ResultModel;
import com.be.beadmin.project.dto.input.BatchPlanDto;
import com.be.beadmin.project.dto.input.BatchPlanInfoFormDto;
import com.be.beadmin.system.service.ProjectDesignSevice.BatchPlanPdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.text.ParseException;
import java.util.List;

/**
 * @Description:
 * @author: Jiaming Zheng
 * @Date: Create in 10:24 2023/6/20
 * @Modified By:
 **/
@Api(tags = {"项目-设计公共模块-批次计划"})
@RestController
public class BatchPlanPdController {

    @Autowired
    private BatchPlanPdService batchPlanPdService;

    @ApiOperation("发布一个项目批次计划")
    @PostMapping("/project/issueBatchPlan")
    public ResultModel issueBatchPlan(@ApiParam(value = "批次计划id") @RequestParam String batchPlanId) {
        try {
            batchPlanPdService.issueBatchPlan(batchPlanId);
        return ResultModel.success("发布成功");
        }
        catch (Exception e) {
            return ResultModel.error(-2, e.getMessage());
        }
//        catch (Exception e) {
//            return ResultModel.error(-3, e.getMessage());
//        }
    }

    @ApiOperation("批量发布项目批次计划")
    @PostMapping("/project/releaseBatchPlan")
    public ResultModel issueBatchPlans(@RequestBody List<String> batchPlanIds) throws Exception {
//        try {

            return ResultModel.success(batchPlanPdService.issueBatchPlans(batchPlanIds));
//        }
//        catch (Exception e) {
//            return ResultModel.error(-2, e.getMessage());
//        }
//        catch (Exception e) {
//            return ResultModel.error(-3, e.getMessage());
//        }
    }
    @ApiOperation("删除一个项目批次计划")
    @PostMapping("/project/delBatchPlan")
    public ResultModel delBatchPlan(@RequestBody BatchPlanDto batchPlanDto){
        batchPlanPdService.delBatchPlan(batchPlanDto.getId());
        return ResultModel.success(ResultModel.DELETE);
    }

    @ApiOperation("添加一个项目批次计划")
    @PostMapping("/project/addBatchPlan")
    public ResultModel addBatchPlan(@RequestBody BatchPlanInfoFormDto batchPlanDto){
//        batchPlanService.addBatchPlan(batchPlanDto);
//        return ResultModel.success(ResultModel.ADD);
        batchPlanPdService.addBatchPlan(batchPlanDto);

        return ResultModel.success(ResultModel.ADD);

    }
}
